home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINICONS / V12N11.ZIP / ABOUT.ZIP / ABOUT.CPP next >
C/C++ Source or Header  |  1993-03-30  |  7KB  |  241 lines

  1. //
  2. //  About box object for C++ OWL
  3. //
  4. //  Copyright 1993 by Danny Thorpe
  5. //
  6.  
  7. #include "about.h"
  8.  
  9. TCreditWindow::TCreditWindow(PTWindowsObject AParent,
  10.                   LPCSTR ABitmapName, LPSTR AStringList[])
  11.         : TWindow(AParent, NULL)
  12. {
  13.   HDC DC;
  14.   HFONT OldFont;
  15.   TEXTMETRIC TM;
  16.   LPSTR P;
  17.  
  18.   Attr.Style = WS_CHILD | WS_VISIBLE;
  19.   Bitmap = LoadBitmap(GetApplication()->hInstance, ABitmapName);
  20.   if (!Bitmap)
  21.   {
  22.     Status = EM_INVALIDWINDOW;
  23.     return;
  24.   };
  25.   GetObject(Bitmap, sizeof(BitSize), &BitSize);
  26.   ScrollPos = 0;
  27.   DC = GetDC(0);
  28.   ScrollUnit = 2;
  29.   ScrollRate = 80;
  30.   OldFont = SelectObject(DC, GetStockObject(ANSI_VAR_FONT));
  31.   GetTextMetrics(DC, &TM);
  32.   FontHeight = TM.tmHeight + TM.tmExternalLeading + 5;
  33.   SelectObject(DC, OldFont);
  34.   ReleaseDC(0, DC);
  35.   StringList = AStringList;
  36.  
  37.   // Count strings in stringlist.
  38.   for (StringCount = 0; StringList[StringCount]; StringCount++);
  39. };
  40.  
  41. TCreditWindow::~TCreditWindow()
  42. {
  43.   DeleteObject(Bitmap);
  44. };
  45.  
  46. void TCreditWindow::GetWindowClass(WNDCLASS& WC)
  47. {
  48.   TWindow::GetWindowClass(WC);
  49.   WC.style = CS_BYTEALIGNWINDOW;   // for BitBlt speed 
  50.   WC.hbrBackground = GetStockObject(BLACK_BRUSH);
  51. };
  52.  
  53. void TCreditWindow::SetupWindow()
  54. {
  55.   TWindow::SetupWindow();
  56.   SetWindowPos(HWindow, 0, 0, 0, BitSize.bmWidth, BitSize.bmHeight,
  57.                SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
  58. };
  59.  
  60. void TCreditWindow::WMDestroy(RTMessage Msg)
  61. {
  62.   if (ScrollPos) // We're scrolling and need to kill the timer 
  63.   {
  64.     KillTimer(HWindow, 1);
  65.     ScrollPos = 0;
  66.   };
  67.   TWindow::WMDestroy(Msg);
  68. };
  69.  
  70. void DrawBitmap(HDC DC, int X, int Y, int W, int H, HBITMAP Bitmap)
  71. {
  72.   HDC MemDC = CreateCompatibleDC(DC);
  73.   HBITMAP OldBits = SelectObject(MemDC, Bitmap);
  74.   BitBlt(DC, X, Y, W, H, MemDC, 0, 0, SRCCOPY);
  75.   SelectObject(MemDC, OldBits);
  76.   DeleteDC(MemDC);
  77. };
  78.  
  79. void TCreditWindow::Paint(HDC DC, PAINTSTRUCT& PS)
  80. {
  81.   RECT R;
  82.   int FirstLine, LastLine, Y;
  83.  
  84.   SaveDC(DC);
  85.   SetViewportOrg(DC, 0, -ScrollPos);
  86.   OffsetRect(&PS.rcPaint, 0, ScrollPos);
  87.   R.left = 0;
  88.   R.top = 0;
  89.   R.right = Attr.W;
  90.   R.bottom = Attr.H;
  91.   if (IntersectRect(&R, &PS.rcPaint, &R))
  92.   {
  93.     DrawBitmap(DC, 0, 0, Attr.W, Attr.H, Bitmap);
  94.     if ((R.top < PS.rcPaint.top) && (R.bottom > PS.rcPaint.top))
  95.       PS.rcPaint.top = R.bottom;
  96.     if ((R.top < PS.rcPaint.bottom) && (R.bottom > PS.rcPaint.bottom))
  97.       PS.rcPaint.bottom = R.top;
  98.     if (PS.rcPaint.top > PS.rcPaint.bottom)
  99.       PS.rcPaint.top = PS.rcPaint.bottom;
  100.   };
  101.   if (ScrollPos > 0)    // we're scrolling 
  102.   {
  103.     FirstLine = (PS.rcPaint.top - Attr.H) / FontHeight;
  104.     if (FirstLine < 0)
  105.       FirstLine = 0;
  106.     if (FirstLine < StringCount)
  107.     {                             // we have text to draw 
  108.       SetTextAlign(DC, TA_CENTER);
  109.       SetBkColor(DC, 0);
  110.       SetTextColor(DC, RGB(0xff,0xff,0xff));
  111.       LastLine = (PS.rcPaint.bottom - Attr.H) / FontHeight;
  112.       for (Y = FirstLine; Y <= LastLine; Y++)
  113.       {
  114.         if (Y < StringCount)
  115.           TextOut(DC, Attr.W / 2, Y*FontHeight + Attr.H,
  116.                       StringList[Y], _fstrlen(StringList[Y]));
  117.       };
  118.     };
  119.                             // Paint second image of bitmap at bottom 
  120.     if (PS.rcPaint.bottom > (Attr.H + FontHeight * StringCount))
  121.       DrawBitmap(DC, 0, Attr.H + FontHeight * StringCount,
  122.                      Attr.W, Attr.H, Bitmap);
  123.   };
  124.   RestoreDC(DC, -1);
  125. };
  126.  
  127. void TCreditWindow::ShowCredits()
  128. {
  129.   SetTimer(HWindow, 1, ScrollRate, NULL);
  130. };
  131.  
  132. void TCreditWindow::WMTimer(RTMessage)
  133. {
  134.   ScrollPos += ScrollUnit;
  135.   // Check to see if it's time to stop scrolling 
  136.   if (ScrollPos > Attr.H + FontHeight * StringCount)
  137.   {
  138.     ScrollPos = 0;
  139.     KillTimer(HWindow, 1);
  140.     InvalidateRect(HWindow, NULL, FALSE);
  141.   }
  142.   else
  143.     ScrollWindow(HWindow, 0, -ScrollUnit, NULL, NULL);
  144.   UpdateWindow(HWindow);
  145. };
  146.  
  147. //*********************************************************
  148.  
  149. TAboutBox::TAboutBox(PTWindowsObject AParent,
  150.                      LPCSTR ATitle,
  151.                      LPCSTR ABitmapName,
  152.                      LPSTR AStringList[],
  153.                      LPSTR AResName) :
  154.      TDialog(AParent, AResName)
  155. {
  156.   Title = _fstrdup(ATitle ? ATitle : "");
  157.   BitmapName = ABitmapName;
  158.   StringList = AStringList;
  159. };
  160.  
  161. TAboutBox::~TAboutBox()
  162. {
  163.   if ( HIWORD(Title) )
  164.     farfree((void*)Title);
  165. };
  166.  
  167. void TAboutBox::SetupWindow()
  168. {
  169.   RECT RDialog,R,RBitWnd,RShade,RBump,ROk;
  170.   int X8, Y8;
  171.   HDC DC;
  172.  
  173.   InitCreditWindow(BitmapName, StringList);
  174.   TDialog::SetupWindow();
  175.   SetWindowText(HWindow, Title);
  176.   DC = GetDC(HWindow);               
  177.   X8 = GetDeviceCaps(DC,LOGPIXELSX) / 8;   // 1/8 inch 
  178.   Y8 = GetDeviceCaps(DC,LOGPIXELSY) / 8;
  179.   ReleaseDC(HWindow, DC);
  180.   GetClientRect(GetDlgItem(HWindow, IDSHADE), &RShade);
  181.   GetClientRect(GetDlgItem(HWindow, IDBUMP), &RBump);
  182.   GetClientRect(GetDlgItem(HWindow, IDOK), &ROk);
  183.   GetClientRect(CreditWindow->HWindow, &RBitWnd);
  184.   RShade.top = Y8;
  185.   RShade.left = X8;
  186.   if (RShade.right < RBitWnd.right + 2*X8)
  187.     RShade.right = RBitWnd.right + 2*X8;
  188.   if (RShade.bottom < RBitWnd.bottom + 2*Y8)
  189.     RShade.bottom = RBitWnd.bottom + 2*Y8;
  190.  
  191.   GetWindowRect(HWindow, &RDialog);
  192.   GetClientRect(HWindow, &R);
  193.   RDialog.right = RDialog.right - RDialog.left - R.right;
  194.   RDialog.bottom = RDialog.bottom - RDialog.top - R.bottom;
  195.   RDialog.right += X8 + RShade.right + X8;   // 1/8 inch margins
  196.   RDialog.bottom +=  Y8 + RShade.bottom
  197.                    + Y8 + RBump.bottom
  198.                    + Y8 + ROk.bottom + Y8;
  199.   if (Parent)
  200.   {
  201.     GetWindowRect(Parent->HWindow, &R);
  202. //         Center dialog in parent's window
  203.     RDialog.left = R.left + (R.right - R.left) / 2
  204.                           - RDialog.right / 2;
  205.     RDialog.top = R.top + (R.bottom - R.top) / 2
  206.                         - RDialog.bottom / 2;
  207.   };
  208.   SetWindowPos(HWindow, 0, RDialog.left, RDialog.top,
  209.                         RDialog.right, RDialog.bottom,
  210.                         SWP_NOACTIVATE | SWP_NOZORDER);
  211.  
  212.   SetWindowPos(GetDlgItem(HWindow, IDSHADE), 0, RShade.left,
  213.                RShade.top, RShade.right, RShade.bottom,
  214.                SWP_NOACTIVATE | SWP_NOZORDER);
  215.   SetWindowPos(CreditWindow->HWindow, 0,  RShade.left + X8,
  216.                RShade.top + Y8, 0, 0,
  217.                SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
  218.  
  219.   RBump.left = -1;
  220.   RBump.right = RDialog.right + 2;
  221.   RBump.top = RShade.top + RShade.bottom + Y8;
  222.   SetWindowPos(GetDlgItem(HWindow, IDBUMP), 0, RBump.left,
  223.                RBump.top, RBump.right, RBump.bottom,
  224.                SWP_NOACTIVATE | SWP_NOZORDER);
  225.  
  226.   GetClientRect(HWindow, &R);
  227.   SetWindowPos(GetDlgItem(HWindow, IDOK), 0,
  228.                R.right / 2 - ROk.right / 2,
  229.                RBump.top + RBump.bottom + Y8, 0, 0,
  230.                SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
  231. };
  232.  
  233. void TAboutBox::InitCreditWindow(LPCSTR ABitmapName, LPSTR AStringList[])
  234. {
  235.   CreditWindow = new TCreditWindow(this, ABitmapName, AStringList);
  236. };
  237.  
  238. void TAboutBox::ShowCredits(RTMessage)
  239. {
  240.   CreditWindow->ShowCredits();
  241. };